#include "stdafx.h"
#include "Protocol.h"
#include "Director.h"

#define DEFAULT_BUF_LENGTH 1024

Protocol::Protocol(void)
{
}


Protocol::~Protocol(void)
{
}

HRESULT Protocol::RecvMsg(SOCKET s)
{
	char buf[DEFAULT_BUF_LENGTH];
	int iRet;
	do
	{
		if (Director::getInstance()->getMode() == kTCP)
		{
			iRet = recv(s, buf, DEFAULT_BUF_LENGTH, 0);
		}
		else if (Director::getInstance()->getMode() == kUDP)
		{
			/*struct addrinfo *ai;
			iRet = recvfrom(s, buf, DEFAULT_BUF_LENGTH, 0, ai->ai_addr, (int *)&ai->ai_addrlen);*/
		}

		if (iRet == SOCKET_ERROR)
		{
			return error_handling("recv() error");
		}
	} while (iRet > 0);
	return iRet;
}

HRESULT Protocol::SendMsg(SOCKET s)
{
	/*int iRet = send(s, src, len, 0);
	if (iRet == SOCKET_ERROR)
	{
		return error_handling("send() error");
	}
	return iRet;*/
	return 0;
}

void Protocol::push(SOCKET fd)
{
	_sockets.push_back(fd);
}